var o = require("./UISoundManager.js"), i = require("./UIPopupBase.js");
cc.Class({
    extends: i,
    properties: {
        tips: {
            default: null,
            type: cc.Label
        },
        headMsg: {
            default: null,
            type: cc.Node
        },
        progress: {
            default: null,
            type: cc.Node
        },
        panelBtn: {
            default: null,
            type: cc.Node
        },
        completeTip: {
            default: null,
            type: cc.Node
        },
        _isShowLabel: !1,
        _firstVote_userId: null
    },
    init: function () {
        Global.notificationCenter.on(Global.eventName.MSG_USER_LEAVE_VOTE, this.voteResult.bind(this), this),
            this.seatInProgress = Global.utils.searchNode(this.progress, "seat");
    },
    transmitData: function (e) {
        console.log("transmitData", e), this.firstVote_userId || (this.firstVote_userId = e.userId),
            this.showHeadMsg(e), this.updateApplyData(e);
    },
    tipOrBtnShow: function (e, t) {
        this.completeTip.active = e, this.panelBtn.active = t;
    },
    showCompleteTip: function (e) {
        var t = this;
        this.tipOrBtnShow(!0, !1), this.schedule(function () {
            --e < 0 || (Global.utils.searchNode(t.completeTip, "time").getComponent(cc.Label).string = "(" + e + ")");
        }, 1);
    },
    showHeadMsg: function (e) {
        var t = this;
        this.tips.string = Global.utils.getFixString(e.name, 5) + " 发起解散牌桌";
        var n = Math.round(e.vote_cd);
        this.firstVote_userId == Global.tableModel.getUserId() ? this.showCompleteTip(n) : this._isShowLabel ? this.showCompleteTip(n) : (this.tipOrBtnShow(!1, !0),
            this.schedule(function () {
                --n < 0 || (Global.utils.searchNode(t.panelBtn, "time").getComponent(cc.Label).string = "(" + n + ")",
                0 == n && Global.msgHandler.requestCustomRoomQuitVote(Global.tableModel.getRoomId(), Global.tableModel.getTableId(), Global.tableModel.getSeatId(), 1));
            }, 1));
    },
    updateApplyData: function (e) {
        this.initHeadMsgAndProgress();
        var t = e.vote_info_detail;
        if (t.length > 0) for (var n = 0; n < t.length; n++) {
            var o = this.headMsg.children[n];
            o.active = !0, this.seatInProgress.children[n].active = !0, 0 == t[n].vote && Global.spriteAtlas.setSpriteFrame(this.seatInProgress.children[n].getComponent(cc.Sprite), "Texture/jiesuan", "no"),
                Global.utils.searchNode(o, "nodeHead").getComponent("HeadController").bindData(t[n].purl),
                o.getChildByName("name").getComponent(cc.Label).string = Global.utils.getFixString(t[n].name, 5);
        }
    },
    initHeadMsgAndProgress: function () {
        for (var e = 0; e < this.headMsg.childrenCount; e++) this.headMsg.children[e].active = !1,
            this.seatInProgress.children[e].active = !1;
    },
    onBtnConfirm: function () {
        Global.msgHandler.requestUserLeaveVote(Global.tableModel.getRoomId(), Global.tableModel.getTableId(), Global.tableModel.getSeatId(), 1),
            this._isShowLabel = !0;
    },
    onBtnRefuse: function () {
        Global.msgHandler.requestUserLeaveVote(Global.tableModel.getRoomId(), Global.tableModel.getTableId(), Global.tableModel.getSeatId(), 0),
            this._isShowLabel = !0;
    },
    onShowTotalResult: function (e) {
        cc.loader.loadRes("prefabs/nodeGameTotalResult", cc.Prefab, function (t, n) {
            var i = cc.instantiate(n);
            console.log("预制节点===", i);
            var a = Global.utils.searchNode(SceneHelper.getCurScene(), "Node_result");
            if (a && i) {
                a.addChild(i, 10), i.setPosition(cc.p(0, 50));
                var r = i.getComponent("GameTotalResultController");
                console.log("controller === ", r), r.bindData(e), o.playGameEnd();
            }
        });
    },
    voteResult: function (e) {
        var t = this;
        1 == e.close_vote ? setTimeout(function () {
            if (t.closePanel(), e.show_budget && Global.tableModel.getIsShowTotalResult()) {
                console.log("显示大结算。。。");
                var n = Global.tableModel.getTotalResult();
                t.onShowTotalResult(n);
            } else cc.error("大结算显示错误 --- IsShowTotalResult ,data.show_budget:", Global.tableModel.getIsShowTotalResult(), e.show_budget);
        }, 1e3 * e.close_vote_cd) : cc.error("不关闭投票框 --- data.close_vote:", e.close_vote);
    }
})
